/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.bkav.portal.portlet.product.service.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.bkav.portal.portlet.product.model.Order_;
import com.bkav.portal.portlet.product.service.base.Order_LocalServiceBaseImpl;
import com.bkav.portal.portlet.product.service.persistence.Order_Persistence;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;

/**
 * The implementation of the order_ local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.bkav.portal.portlet.product.service.Order_LocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author ducdvd
 * @see com.bkav.portal.portlet.product.service.base.Order_LocalServiceBaseImpl
 * @see com.bkav.portal.portlet.product.service.Order_LocalServiceUtil
 */
public class Order_LocalServiceImpl extends Order_LocalServiceBaseImpl {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never reference this interface directly. Always use {@link com.bkav.portal.portlet.product.service.Order_LocalServiceUtil} to access the order_ local service.
	 */
	public int countAll() throws SystemException{
		return order_Persistence.countAll();
	}
	
	public int countByCompany(long companyId) throws SystemException{
		return order_Persistence.countByCompany(companyId);
	}
	
	public int countByGroup(long groupId) throws SystemException {
		return order_Persistence.countByGroup(groupId);
	}
	
	public List<Order_> findAll() throws SystemException {
		return order_Persistence.findAll();
	}
	
	public List<Order_> findByCompany(long companyId) throws SystemException {
		return order_Persistence.findByCompany(companyId);
	}
	
	public Order_ addOrder(long companyId, long groupId,
			long userId, String userName, long productId, String email,
			String orderSL) throws SystemException,
			PortalException {

		Date now = Calendar.getInstance().getTime();

		long orderId = counterLocalService.increment();

		Order_ order = order_Persistence.create(orderId);

		order.setCompanyId(companyId);
		order.setGroupId(groupId);
		order.setUserId(userId);
		order.setUserName(userName);
		order.setProductId(productId);
		order.setEmail(email);
		order.setOrderSL(orderSL);
		order.setCreateDate(now);
		order.setModifiedDate(now);

		order_Persistence.update(order, false);

		
		return order;
	}
}